#ifndef WINDOW_H
#define WINDOW_H

#include "Exception.h"
#include "VideoSettings.h"

#define CLASS_NAME "Cvekas window"

namespace Cvekas {

/// %Application window
class Window : public boost::noncopyable 
{
public:
	/// Constructor
	/// \param instace Optional HINSTANCE value, usualy provided by WinMain
	/// \param title %Window title
	/// \param width Width of window in pixels (without borders)
	/// \param height Height of window in pixels (without borders)
	/// \param fullscreen Will the window be fullscreen?
	/// \throws Exception On unsucessful initialization of window
	/// \remarks Not recommeded, use Window(HINSTANCE, const std::string&, VideoSettings&) instead
	Window(HINSTANCE instace, const std::string& title, uint width, uint height, bool fullscreen);
	
	/// Constructor. All values are pulled from global VideoSettings.
	/// \param instace Optional HINSTANCE value, usualy provided by WinMain
	/// \param title %Window title
	Window(HINSTANCE instace, const std::string& title);
	~Window();

	/// Changes window's title
	void setTitle(const std::string& title);
	
	/// Processes window message qeue, must be called every frame.
	/// \returns true if window is not closed
	bool update();
	
	/// Indicates weather window is still active (not closed)
	bool isActive();
	
	/// Returns handle of window
	HWND getHandle();

	/// Shows or hides mouse cursor
	void showCursor(bool show) {show_cursor = show; };

	/// Returns true if cursor is visible
	bool isCursorVisible() { return show_cursor; };

	/// Must be before switching between windowed/fullscreen modes or resolutions.
	void switchMode();

private:
	/// Creates window
	void createWindow(const std::string& title, uint width, uint height, bool fullscreen);
	/// Window message pump
	static LRESULT WINAPI msgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);

	void adjustWindowSize(uint& width, uint& height);

	bool active;
	bool fullscreen;
	bool show_cursor;
	uint width, height;

	WNDCLASSEX win_class;
	HWND handle;
	HINSTANCE instance;
	DWORD style;
	MSG msg;
};

typedef boost::shared_ptr<Window> WindowPtr;

} // namespace

#endif